<?php 

function M($path1, $path2)
{
	$preg = "/\/$/";
	$newPath1 = preg_replace($preg, '', $path1);
	$newPath2 = preg_replace($preg, '', $path2);

	if(!file_exists($newPath2)){
		mkdir($newPath2,777,true);
	}

	if(is_dir($newPath1)){
		$files = glob($newPath1."/*");
		foreach ($files as $value) {
			$url = str_replace($path1, $path2, $value);
			if(is_dir($value)){
				M($value, $url);
			}else{
				copy($value,$url);
			}
		}
	}


}


M('./test','./test2');









 ?>